<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        .time-item {
            width: 450px;
            height: 45px;
            margin: 0 auto;
        }

        .time-item strong {
            background: orange;
            color: #fff;
            line-height: 49px;
            font-size: 36px;
            font-family: Arial;
            padding: 0 10px;
            margin-right: 10px;
            border-radius: 5px;
            box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.2);
        }

        .time-item>span {
            float: left;
            line-height: 49px;
            color: orange;
            font-size: 32px;
            margin: 0 10px;
            font-family: Arial, Helvetica, sans-serif;
        }

        .title {
            width: 260px;
            height: 50px;
            margin: 200px auto 50px auto;
        }
    </style>

</head>

<body>
    <h1 class="title">距离光棍节，还有</h1>

    <div class="time-item">
        <span><span id="day">00</span>天</span>
        <strong><span id="hour">00</span>时</strong>
        <strong><span id="minute">00</span>分</strong>
        <strong><span id="second">00</span>秒</strong>
    </div>
    <script>
        window.onload = function () {
            let day = document.querySelector('#day');
            let hour = document.querySelector('#hour');
            let minute = document.querySelector('#minute');
            let second = document.querySelector('#second');
            const theDay = "2021-11-11 0:0:0"
            let end = new Date(theDay);
            let endTime = end.getTime();
            cutdown();
            setInterval(cutdown, 1000)
            function cutdown() {
                let now = new Date();
                let nowTime = now.getTime();
                let time = (endTime - nowTime) / 1000;
                var days, hours, minutes, seconds;

                days = Math.floor(time / 60 / 60 / 24);
                hours = Math.floor(time / 60 / 60 % 24);
                minutes = Math.floor(time / 60 % 60);
                seconds = Math.floor(time % 60);
                day.innerText = days;
                hour.innerText = hours;
                minutes.innerText = minute;
                second.innerText = seconds;
            }
        }
    </script>
</body>

</html>